/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2022-10-24
 * Time: 19:03
 */
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int a = 0,b = 1,c = 1,n=0;

        while(sc.hasNext()){
            n = sc.nextInt();
        }
        while(c < n){
            a = b;
            b = c;
            c = a+b;
        }
        int x = n-b;
        int y = c-n;
        System.out.print(x>y?y:x);
    }
}
